package com.spring.demo1;

import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.Map;

/**
 * @author vhans
 */
@AnnUse("用在了类上")
public class AnnUseTest<@AnnUse("用在了类变量类型V1上") V1, @AnnUse("用在了类变量类型V2上") V2> {

    private Map<@AnnUse("用在了泛型类型上") String, Integer> map;

    public <@AnnUse("用在了参数上") T> String m1() {
        return null;
    }

    public static void main(String[] args) throws NoSuchMethodException {
        for (TypeVariable typeVariable : AnnUseTest.class.getTypeParameters()) {
            print(typeVariable);
        }

        for (TypeVariable typeVariable : AnnUseTest.class.getDeclaredMethod("m1").getTypeParameters()) {
            print(typeVariable);
        }
    }

    private static void print(TypeVariable typeVariable) {
        System.out.println("类型变量名称:" + typeVariable.getName());
        Arrays.stream(typeVariable.getAnnotations()).forEach(System.out::println);
    }
}
